﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using DiscoveryLogic.Common.Utilities;

namespace DiscoveryLogic.Analytics.DataObjects.Rules
{
    public class ArgumentFieldBinding
    {
        public string ArgumentName;
        public bool FromSrcEntity;
        public bool FromTgtEntity;
        public string PropertyName;

        public void Save(ref XmlDocument xDoc, XmlNode bindingNode)
        {
            XmlDataUtil.UpdateAttribute(ref xDoc, bindingNode, "ArgName",this.ArgumentName);
            XmlDataUtil.UpdateAttribute(ref xDoc, bindingNode, "FromSrcEntity", this.FromSrcEntity.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, bindingNode, "FromTgtEntity", this.FromTgtEntity.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, bindingNode, "PropName", this.PropertyName);
        }

        public static ArgumentFieldBinding Read(XmlNode bindingNode)
        {
            ArgumentFieldBinding argBinding=new ArgumentFieldBinding();
            argBinding.ArgumentName = XmlDataUtil.GetAttributeValue(bindingNode, "ArgName", "");
            argBinding.FromSrcEntity = bool.Parse(
                XmlDataUtil.GetAttributeValue(bindingNode, "FromSrcEntity", false.ToString()));
            argBinding.FromTgtEntity = bool.Parse(
                XmlDataUtil.GetAttributeValue(bindingNode, "FromTgtEntity", false.ToString()));
            argBinding.PropertyName = XmlDataUtil.GetAttributeValue(bindingNode, "PropName", "");
            return argBinding;
        }
    }
}
